//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/.
// 

// Created: 2012-5-25 for project ex5

import inet.networklayer.autorouting.FlatNetworkConfigurator;
import inet.nodes.inet.ExtRouter;
import inet.nodes.inet.Router;

import inet.nodes.inet.StandardHost;
import inet.nodes.inet.StandardHostWithDLThruputMeter;
import ned.DatarateChannel;



//
// A generated network with k-ary tree topology.
//
network Operator
{
    parameters:
        int levels = default(2);  // 1 = root only
        int k = default(5); // tree branching factor
        int isdn = default(25); // number of isdn Clients per Accessrouter
        @display("bgb=4000,2000");
    submodules:
        node[(k^levels-1) / (k-1)]: Router {
            gates:
                pppg[1+k];
        }
        accessRouter[k^(levels)]: Router {
            gates:
                pppg[1+isdn];
        }
        isdnClient[(k^(levels))*isdn]: StandardHostWithDLThruputMeter {
            gates:
                pppg[1];
        }
        Internet: StandardHost {
            @display("i=device/server");
        }
        flatNetworkConfigurator: FlatNetworkConfigurator {
        }
    connections allowunconnected:
        node[0].pppg[0] <--> DatarateChannel <--> Internet.pppg++; //Gatewayrouter connected to Internet
        
        for i=1..k {											// Backbone Routers connected to Gatewayrouter
            node[i].pppg[0] <--> {  delay = 10ms; datarate = 10 Mbps; } <--> node[floor((i-1)/k)].pppg[1+i%k];
        }
        
        for i=0..sizeof(accessRouter)-1 {						// AccessRouters connected to Backbone Routers
            accessRouter[i].pppg[0] <--> {  delay = 15 ms; datarate = 2 Mbps; } <--> node[floor((i)/k)+1].pppg[1+i%k];
        }
        
        for i=0..sizeof(isdnClient)-1 {							// Clients connected to Accessrouters
            isdnClient[i].pppg[0] <--> {  delay = 40ms; datarate = 64kbps; } <--> accessRouter[floor((i)/isdn)].pppg[1+i%isdn];
        }
}
